#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstring>
using namespace std;
const int N = 1009;
int g[N][N];
struct Div
{
	int div, num=0;
}div_r[N],div_c[N];
bool cmp_num(const Div& a, const Div& b)
{
	return a.num > b.num;
}
bool cmp_div(const Div& a, const Div& b)
{
	return a.div < b.div;
}
int main()
{
	int  m,n, k, l, d;
	cin >> m >> n >> k >> l >> d;
	for (int i = 1; i <= m; i++)
	{
		div_r[i].div = i;
	}
	for (int i = 1; i <= n; i++)
	{
		div_c[i].div = i;
	}
	for(int i=1;i<=d;i++)
	{
		int x, y, p, q;
		scanf("%d%d%d%d", &x, &y, &p, &q);
		if (x == p)
		{
			div_c[min(y,q)].num++;
		}
		else if (y == q)
		{
			div_r[min(x,p)].num++;
		}
	}
	sort(div_r + 1, div_r + m, cmp_num);
	sort(div_c + 1, div_c + n, cmp_num);

	sort(div_r + 1, div_r + k + 1, cmp_div);
	sort(div_c + 1, div_c + l + 1, cmp_div);

	for (int i = 1; i <= k; i++)printf("%d ", div_r[i].div);
	printf("\n");
	for (int i = 1; i <= l; i++)printf("%d ", div_c[i].div);
	return 0;
}
